package pt.ua.helpdesk.client;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

/**
 * Login service. This is a remote service and logins
 * the user into the system
 * @author Amigos do Noddy
 *
 */
public interface ServiceLogin extends RemoteService {
	/**
	 * Checks whether the user and password are valid in
	 * the system
	 * 
	 * @param username Username
	 * @param pass Password
	 * @return Array list containing the id, username and user type on success
	 */
	ArrayList loginCheck(String username, String pass);
	
	/**
	 * Registers a user in the system
	 * 
	 * @param username Username
	 * @param pass Password
	 * @param Email Email
	 * @param name Name
	 * @return Returns a string with the error codes
	 */
	String registar(String username, String pass, String Email, String name);
	
	/**
	 * Activates an account
	 * 
	 * @param email Email
	 * @param codigo Activation code
	 * @return True in the case of success
	 */
	Boolean activar(String email, long codigo);
	
	/**
	 * Resets the user password
	 * @param email Email
	 * @return True in the case of success
	 */
	Boolean novapass(String email);
	
	/**
	 * Edits the user account
	 * 
	 * @param username Username
	 * @param pass Password
	 * @return True in the case of success
	 */
	Boolean editaccount(String username, String pass, String pass2);
	
	/**
	 * Utility class for simplifying access to the instance of async service.
	 */
	public static class Util {
		private static ServiceLoginAsync instance;
		public static ServiceLoginAsync getInstance(){
			if (instance == null) {
				instance = (ServiceLoginAsync) GWT.create(ServiceLogin.class);
				ServiceDefTarget target = (ServiceDefTarget) instance;
				target.setServiceEntryPoint(GWT.getModuleBaseURL() + "ServiceLogin");
			}
			return instance;
		}
	}
}
